/**
 * 
 */
package neptune.web.client.commands;

import neptune.web.client.model.DefaultRoles;
import neptune.web.client.services.ApplicationDataProvider;
import neptune.web.client.view.OperativeView;
import neptune.web.client.view.View;
import neptune.web.client.view.ViewManager;
import neptune.web.client.view.components.dialogs.HelpDialog;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;

/**
 * Richiama una HelpDialog. La HelpDialog puntera' ad una pagina web il cui url
 * e' costruito nel seguente modo: <br>
 * <br>
 * [WEB APPLICATION BASE URL]/[ViewName].[ROLE LABEL].help.html <br>
 * <br>
 * [ROLE LABEL] = admin | user
 * 
 * 
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class HelpCommand implements Command {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.gwt.user.client.Command#execute()
	 */
	public void execute() {
		// Recupera il nome della view attualmente visualizzata
		String viewName = null;
		View view = ViewManager.getViewManager().getActiveView();
		viewName = view.getName();
		if (view instanceof OperativeView) {
			OperativeView operative = (OperativeView) view;
			view = operative.getActiveView();
			if (view != null)
				viewName = view.getName();
			else
				viewName = operative.getName();
		}

		String roleString;
		String role = ApplicationDataProvider.getInstance()
				.getActualUserRole();
		if (role.equals(DefaultRoles.SYSTEM_ADMIN))
			roleString = "admin";
		else
			roleString = "user";

		HelpDialog dialog = new HelpDialog(GWT.getModuleBaseURL() + viewName
				+ "." + roleString + ".help.html");
		dialog.center();
	}
}
